<template>
  <el-dialog
    :before-close="handleClose"
    :show="show"
    :visible.sync="visible"
    title="查看服务器信息"
    width="70%"
    @close="$emit('update:show', false)"
  >
    <el-row>
      <el-col :span="3">服务器ID: </el-col>
      <el-col :span="5">{{ viewItem.id }}</el-col>
      <el-col :span="3">Intranet: </el-col>
      <el-col :span="5">{{ viewItem.intranet }}</el-col>
      <el-col :span="3">ZLMediaKit ServerId: </el-col>
      <el-col :span="5">{{ viewItem.server_id_zlk }}</el-col>
    </el-row>
    <el-row>
      <el-col :span="3">Media IP: </el-col>
      <el-col :span="5">{{ viewItem.media_ip }}</el-col>
      <el-col :span="3">Http端口: </el-col>
      <el-col :span="5">{{ viewItem.http_port }}</el-col>
      <el-col :span="3">Https端口: </el-col>
      <el-col :span="5">{{ viewItem.https_port }}</el-col>
    </el-row>
    <el-row>
      <el-col :span="3">rtmp 端口: </el-col>
      <el-col :span="5">{{ viewItem.rtmp_port }}</el-col>
    </el-row>

    <!-- 表格区域，用来加载流列表 -->
    <el-table :data="streamList" style="width: 100%">
      <el-table-column label="app" prop="app" width="70" />
      <el-table-column label="stream" prop="stream" width="360" />
      <el-table-column label="协议" prop="schema" width="60" />
      <el-table-column label="在线" prop="readerCount" width="60" />
      <el-table-column label="时长(秒)" prop="aliveSecond" width="80" />
      <el-table-column label="速度" prop="bytesSpeed" width="100" />
      <el-table-column label="mp4录像" prop="isRecordingMP4" width="90">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.isRecordingMP4" type="success">录像中</el-tag>
          <el-tag v-else type="danger">未录像</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="流类型" prop="originTypeStr" width="80" />
      <el-table-column label="源地址" prop="originUrl" />
    </el-table>
    <span slot="footer" class="dialog-footer">
      <el-button
        @click="visible = false"
      >关闭</el-button>
    </span>
  </el-dialog>

</template>

<script>
const TAG = '[媒体服务器]'
import { listStreams as apiGetStreamList } from '@/api/zlMediaKit'

export default {
  name: 'VideoDialog',
  props: {
    show: {
      type: Boolean,
      default: false
    },
    viewItem: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {
      visible: false,
      streamList: []
    }
  },
  watch: {
    show(val) {
      this.visible = val
      console.info(TAG, 'mounted', this.viewItem)
      this.getStreamList()
    }
  },
  methods: {
    handleClose(done) {
      this.$emit('update:show', false)
      done()
    },
    getStreamList() {
      apiGetStreamList({ server_id: this.viewItem.id }).then(res => {
        console.info(TAG, 'getStreamList', res)
        this.streamList = res.data.data
      })
    }
  }
}
</script>
